/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Vent.java
 *
 * Created on 21/04/2011, 06:14:11 PM
 */

package algrt;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.image.BufferedImage;

/**
 *
 * @author Damn
 */
public class Vent extends javax.swing.JFrame {
 int [] frm1;
 int [] frm2;
 int[] frmRes;
 BufferedImage bfIfrm1=null;
 BufferedImage bfIfrm2=null;
 BufferedImage bfTResult=null;


    /** Creates new form Vent */
    public Vent() {
        initComponents();

         try{
//        new  Vent().setVisible(true);
            String srcFrm1= "nf1.bmp";
            String srcFrm2=  "nff1.bmp";

            frm1=new ImMatr().abrirImagen(srcFrm1);
            frm2=new ImMatr().abrirImagen(srcFrm2);
            //frm2=new ImMatr().dilate(frm2, 100,  1);
            bfIfrm1=pintarZonas( frm1, 100, 1);
            bfIfrm2=pintarZonas( frm2, 100, 2);

            Comparador compFunction=new Comparador();
            frmRes=compFunction.compararRGBZonas(bfIfrm1, bfIfrm2);
            bfTResult=mostrarFirmaResultado(frmRes, 200, 3);
            //nulos?
            txtAResult.setText(new Comparador().obtenerResultadosCompar(frmRes));
           // new ImMatr().muestraRGB(frmRes, 200);
            lblf1.setText(srcFrm1);
            lblf2.setText(srcFrm2);
        }catch(Exception e){
            e.printStackTrace();
        }

    }

  
    public void paint(Graphics g){
        try{
            paintComponents(g);
            
            mostrarFirmaResultado(frmRes, 200, 3);
            g.drawImage(bfIfrm1, 10, 100, rootPane);
            g.drawImage(bfIfrm2, 230, 100, rootPane);
            g.drawImage(bfTResult, 450, 100, rootPane);
        }catch(Exception e){
          
        }
    }



    public BufferedImage mostrarFirma (int[] afrm, int ancho,int pos){
        int punto=10+ 205*(pos-1);
        int j=0,k=0;
        BufferedImage bfImg=new BufferedImage(100, 50, BufferedImage.TYPE_INT_RGB);

        Graphics a=bfImg.getGraphics();
        a.setColor(Color.white);
        for (int i=0;i<afrm.length;i++){
             a.setColor(Color.white);
             a.drawOval(k, j, 2, 2);
             k++;
            if (i>=ancho && (i %ancho==0)){
                j++;
                k=0;
            }
        }
        k=0;j=0;
         for (int i=0;i<afrm.length;i++){
             
             if (afrm[i]!=Color.white.getRGB()){
                    a.setColor(new Color(afrm[i]));
                    a.drawOval(k+3, j+3, 1, 1);
             }else{
                  a.setColor(Color.white);
                  a.drawOval(k+3, j+3, 1, 1);
                  
             }
              //System.out.print(afrm[i]);
              k++;
              
            if (i>=ancho && (i %ancho==0)){
                j++;
               // a.drawOval(k, j, 15, 15);
               // System.out.print(" \n");
                k=0;
            }       
        }

        //agranda la imagen
        BufferedImage bf2= new BufferedImage(200, 100, BufferedImage.TYPE_INT_RGB);
        Graphics g2=bf2.createGraphics();
        g2.drawImage(bfImg, 0, 0, 200, 100, null);
        return bf2;
    }


    public BufferedImage pintarZonas(int[] afrm, int ancho,int pos){
        int punto=10+ 205*(pos-1);
        int j=0,k=0;
        BufferedImage bfImg=new BufferedImage(100, 50, BufferedImage.TYPE_INT_RGB);

        Graphics a=bfImg.getGraphics();

         for (int i=0;i<afrm.length;i++){
             a.setColor(Color.white);
             a.drawOval(k, j, 2, 2);
             k++;
            if (i>=ancho && (i %ancho==0)){
                j++;
                k=0;
            }
        }
        j=0;
        k=0;
        if (pos!=2)
         for (int i=0;i<afrm.length;i++){
                 if (afrm[i]==Color.black.getRGB()){
                    a.setColor(Color.blue);
                    a.drawOval(k, j, 8, 8);
                 }
                 k++;
                if (i>=ancho && (i %ancho==0)){
                    j++;
                    k=0;
                }
            }
        j=0;
        k=0;
        if (pos!=2)
         for (int i=0;i<afrm.length;i++){
             if (afrm[i]==Color.black.getRGB()){
                 a.setColor(Color.red);
                 a.drawOval(k+2, j+2, 4, 4);

             }

             k++;
            if (i>=ancho && (i %ancho==0)){
                j++;
                k=0;
            }
        }
        j=0;
        k=0;
        
         for (int i=0;i<afrm.length;i++){
             if (afrm[i]==Color.black.getRGB()){
                a.setColor(Color.black);
                a.drawOval(k+3, j+3, 2, 2);
            }
             k++;

            if (i>=ancho && (i %ancho==0)){
                j++;
                k=0;
            }
        }

        //agranda la imagen
        BufferedImage bf2= new BufferedImage(200, 100, BufferedImage.TYPE_INT_RGB);
        Graphics g2=bf2.createGraphics();
        g2.drawImage(bfImg, 0, 0, 200, 100, null);
        return bf2;
    }

     public BufferedImage mostrarFirmaResultado (int[] afrm, int ancho,int pos){
        int punto=10+ 205*(pos-1);
        int j=0,k=0;
        BufferedImage bfImg=new BufferedImage(200, 100, BufferedImage.TYPE_INT_RGB);

        Graphics a=bfImg.getGraphics();
        //a.setColor(Color.white);
     
        
         for (int i=0;i<afrm.length;i++){

             if (afrm[i]!=Color.white.getRGB()){
                    a.setColor(new Color(afrm[i]));
                    a.drawOval(k, j, 1, 1);
             }else{
                  a.setColor(Color.white);
                  a.drawOval(k, j, 1, 1);

             }
              //System.out.print(afrm[i]);
              k++;

            if (i>=ancho && (i %ancho==0)){
                j++;
               // a.drawOval(k, j, 15, 15);
               // System.out.print(" \n");
                k=0;
            }
        }

        return bfImg;

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        lblResult = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        txtAResult = new javax.swing.JTextArea();
        lblf1 = new javax.swing.JLabel();
        lblf2 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setText("Original");

        jLabel2.setText("Test");

        jLabel3.setText("******************Anàlisis Pixeles*******************");

        txtAResult.setColumns(20);
        txtAResult.setFont(new java.awt.Font("Monospaced", 1, 13)); // NOI18N
        txtAResult.setRows(5);
        txtAResult.setEnabled(false);
        jScrollPane1.setViewportView(txtAResult);

        lblf1.setText("jLabel4");

        lblf2.setText("jLabel5");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(41, 41, 41)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(lblf1))
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblResult)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(183, 183, 183)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(lblf2)
                                    .addComponent(jLabel2)))))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(90, 90, 90)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 216, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(57, 57, 57)
                        .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 310, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(299, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2))
                .addGap(144, 144, 144)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblf1)
                    .addComponent(lblf2))
                .addGap(16, 16, 16)
                .addComponent(lblResult)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
    * @param args the command line arguments
    */
   

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel lblResult;
    private javax.swing.JLabel lblf1;
    private javax.swing.JLabel lblf2;
    private javax.swing.JTextArea txtAResult;
    // End of variables declaration//GEN-END:variables

}
